#include <string>
#include <stack>
#include <iostream>

using namespace std;

class Solution 
{
public:
    bool isValid(string s) 
    {
        stack<char> store;
        for(int i = 0; i < s.length(); i++)
        {
            if(s[i] == '(' || s[i] == '{' || s[i] == '[')
            {
                store.push(s[i]);
            }
            else if(s[i] == ')')
            {
                if(store.empty() || store.top() != '(')
                {
                    return false;
                }
                store.pop();
            }
            else if(s[i] == '}')
            {
                if(store.empty() || store.top() != '{')
                {
                    return false;
                }
                store.pop();
            }
            else if(s[i] == ']')
            {
                if(store.empty() || store.top() != '[')
                {
                    return false;
                }
                store.pop();
            }
            else
            {
                return false;
            }
        }
        if(store.empty())
        {
            return true;
        }
        return false;
    }
};

int main()
{
    Solution solution;

    // 测试案例1: 有效括号
    string test1 = "()";
    cout << "测试案例1: " << test1 << endl;
    cout << "结果: " << (solution.isValid(test1) ? "true" : "false") << endl;
    cout << "预期: true" << endl << endl;

    // 测试案例2: 有效括号
    string test2 = "()[]{}";
    cout << "测试案例2: " << test2 << endl;
    cout << "结果: " << (solution.isValid(test2) ? "true" : "false") << endl;
    cout << "预期: true" << endl << endl;

    // 测试案例3: 无效括号 - 奇数长度
    string test3 = "(";
    cout << "测试案例3: " << test3 << endl;
    cout << "结果: " << (solution.isValid(test3) ? "true" : "false") << endl;
    cout << "预期: false" << endl << endl;

    // 测试案例4: 无效括号 - 右括号多余
    string test4 = "(()";
    cout << "测试案例4: " << test4 << endl;
    cout << "结果: " << (solution.isValid(test4) ? "true" : "false") << endl;
    cout << "预期: false" << endl << endl;

    // 测试案例5: 无效括号 - 左括号多余
    string test5 = "())";
    cout << "测试案例5: " << test5 << endl;
    cout << "结果: " << (solution.isValid(test5) ? "true" : "false") << endl;
    cout << "预期: false" << endl << endl;

    // 测试案例6: 有效括号 - 嵌套
    string test6 = "{[]}";
    cout << "测试案例6: " << test6 << endl;
    cout << "结果: " << (solution.isValid(test6) ? "true" : "false") << endl;
    cout << "预期: true" << endl << endl;

    // 测试案例7: 无效括号 - 括号数量匹配但顺序错误
    string test7 = "([)]";
    cout << "测试案例7: " << test7 << endl;
    cout << "结果: " << (solution.isValid(test7) ? "true" : "false") << endl;
    cout << "预期: false（但你的Solution可能返回true）" << endl << endl;

    return 0;
}